package main

import (
	"go-web-learning/src/04_gorm/db"
	"gorm.io/gorm"
)

var DB = db.DB

func main() {
	useTransaction()
}

func useTransaction() {
	DB.Transaction(func(tx *gorm.DB) error {
		tx.Create(&db.AuthModel{
			Name: "no err",
		})
		tx.Create(&db.AuthModel{
			Name: "err",
		})
		//return errors.New("test")
		return nil
	})
}

func manualTransaction() {
	tx := DB.Begin()
	tx.Create(&db.AuthModel{
		Name: "no err",
	})
	tx.Create(&db.AuthModel{
		Name: "err",
	})
	//tx.Rollback()
	tx.Commit()
}
